/* jQuery flexImages v1.0.4 Copyright (c) 2014 Simon Steinberger / Pixabay GitHub: https://github.com/Pixabay/jQuery-flexImages License: http://www.opensource.org/licenses/mit-license.php */ (function($){ $.fn.flexImages = function(options){ var o = $.extend({ container: '.item', object: 'img', rowHeight: 180, maxRows: 0, truncate: 0 }, options); return this.each(function(){ var grid = $(this), containers = $(grid).find(o.container), items = [], t = new Date().getTime(), s = window.getComputedStyle ? getComputedStyle(containers[0], null) : containers[0].currentStyle; o.margin = (parseInt(s.marginLeft) || 0) + (parseInt(s.marginRight) || 0) + (Math.round(parseFloat(s.borderLeftWidth)) || 0) + (Math.round(parseFloat(s.borderRightWidth)) || 0); for (j=0;j o.maxRows || o.truncate && lastRow && rows > 1) row[x][0].style.display = 'none'; else { if (row[x][4]) { row[x][3].attr('src', row[x][4]); row[x][4] = ''; } row[x][0].style.width = new_w+'px'; row[x][0].style.height = row_h+'px'; row[x][0].style.display = 'block'; } } for (i=0; i= max_w) { var margins_in_row = row.length * o.margin; ratio = (max_w-margins_in_row) / (row_width-margins_in_row), row_h = Math.ceil(o.rowHeight*ratio), exact_w = 0, new_w; for (x=0; x max_w) new_w -= exact_w - max_w; _helper(); } // reset for next row row = [], row_width = 0; rows++; } } // layout last row - match height of last row to previous row for (x=0; x